package com.zhuss.aop;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.zhuss.exception.OceanException;

@Aspect
@Component
public class CheckAspect {
	
	Logger  LOGGER = LoggerFactory.getLogger(MybatisSqlInterceptor.class); 
	
	@Pointcut("execution(public * com.zhuss.common.Processor.process(java.lang.Object))")
	public void pointCut() {
		
	}
	
	@Before("pointCut()")
	public void around(JoinPoint point) throws Throwable {
		String targetName = point.getTarget().getClass().getName();
        // String methodName = point.getSignature().getName();
        Object[] arguments = point.getArgs();
        Class<?> targetClass = Class.forName(targetName);
        Method method = targetClass.getMethod("check", Object.class);
        try {
        	method.invoke(point.getTarget(), arguments[0]);
        } catch (Exception e) {
        	LOGGER.info("e: " + e);
        	if (e instanceof InvocationTargetException) {
        		throw ((OceanException)((InvocationTargetException) e).getTargetException());
        	}
        	throw e;
        }
       /* Object object = point.proceed();
        return object;*/
	}

}
